package com.kexio.file.service;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.kexio.file.storage.StorageStrategy;

/**
 * 存储策略工厂
 * 
 * @author kexio
 */
public class StorageStrategyFactory {

    private final Map<String, StorageStrategy> strategyMap = new ConcurrentHashMap<>();

    public StorageStrategyFactory(List<StorageStrategy> strategies) {
        strategies.forEach(strategy -> 
            strategyMap.put(strategy.getStorageType(), strategy));
    }

    /**
     * 根据存储类型获取策略
     */
    public StorageStrategy getStrategy(String storageType) {
        StorageStrategy strategy = strategyMap.get(storageType);
        if (strategy == null) {
            throw new RuntimeException("不支持的存储类型: " + storageType);
        }
        return strategy;
    }

    /**
     * 获取所有可用的存储类型
     */
    public java.util.Set<String> getAvailableStorageTypes() {
        return strategyMap.keySet();
    }

    /**
     * 检查存储类型是否可用
     */
    public boolean isStorageTypeAvailable(String storageType) {
        return strategyMap.containsKey(storageType);
    }
}
